<?php
session_start();
 if (empty($_SESSION['username']) AND empty($_SESSION['passuser'])){
  echo "<link href='style.css' rel='stylesheet' type='text/css'>
 <center>Untuk mengakses modul, Anda harus login <br>";
  echo "<a href=../../index.php><b>LOGIN</b></a></center>";
}
else{
$aksi="modul/mod_sms/aksi_sms.php";
$upass = $_SESSION['passuser'];
$gu = mysql_query("SELECT username FROM users WHERE password='$upass'");
$uname = mysql_fetch_object($gu);
$usrnm = $uname->username;
	$dmsg = $_GET['msg'];
	if(!empty($dmsg)) {
		echo "<div class='message'>".$dmsg."</div>";
	}
switch($_GET[act]){
  // Inbox
  default:
    echo "<div class='componentheading'>Inbox</div>
		  <input type=button value='Run Service' 
          onclick=\"window.location.href='?module=sms&act=runservice';\">&nbsp;
          <input type=button value='Kirim SMS' 
          onclick=\"window.location.href='?module=sms&act=kirimsms';\">&nbsp;
		  <input type=button value='Sebar SMS' 
          onclick=\"window.location.href='?module=sms&act=sebarsms';\">&nbsp;
		  <input type=button value='Inbox' 
          onclick=\"window.location.href='?module=sms';\">&nbsp;
		  <input type=button value='Terkirim' 
          onclick=\"window.location.href='?module=sms&act=sentitems';\">
		  <p>
          <table class='boslist'>
          <tr><th>No</th><th>Pengirim</th><th>Isi Pesan</th><th>Waktu</th></tr>"; 
    $tampil=mysql_query("SELECT * FROM inbox ORDER BY ReceivingDateTime DESC");
    $no=1;
    while ($r=mysql_fetch_array($tampil)){
       echo "<tr><td align='right'>$no</td>
             <td>$r[SenderNumber]</td>
             <td>$r[TextDecoded]</td>
             <td>$r[ReceivingDateTime]</td></tr>";
      $no++;
    }
    echo "</table></p>";
    break;
  
  case "runservice":
	passthru('c:\xampp\htdocs\bosms\gammu\gammu-smsd -c c:\xampp\htdocs\bosms\gammu\smsdrc -i');
	passthru('c:\xampp\htdocs\bosms\gammu\gammu-smsd -c c:\xampp\htdocs\bosms\gammu\smsdrc -s');
  break;
  
  // Form Kirim SMS
  case "kirimsms":
	echo "
		<script type='text/javascript' language='javascript'>
			checked = false;
			  function checkedAll () {
				if (checked == false){checked = true}else{checked = false}
				for (var i = 0; i < document.sendform.rec.length; i++) {
					document.sendform.rec[i].checked = checked;
				}
			  }

		</script>
	";
    echo "<div class='componentheading'>Form Kirim SMS</div>
          <form method=POST  name='sendform' action='$aksi?module=sms&act=sendsms'>
		  <p>
			<strong>Isi SMS :</strong><br />
			<textarea name='isi' class='teks' style='width:600px; height:200px;'></textarea>
		  </p>
		  <p>
		  <strong>Tujuan :</strong>
		  <table class='boslist'>
			<caption>Pilih Anggota</caption>
			<tr>
				<th><input type='checkbox' name='ckall' onclick='checkedAll()' /></th>
				<th>Nama</th>
				<th>No. HP</th>
			</tr>
		";
		$gl = mysql_query("SELECT * FROM anggota");
		while($rp = mysql_fetch_array($gl)) {
			echo "<tr>
				<td align='center'><input type='checkbox' name='rec[]' value='".$rp[nohp]."' /></td>
				<td>$rp[nama]</td>
				<td>$rp[nohp]</td>
			</tr>";
		}
		echo "
		  </table><br />
		  atau Nomor Bebas : <input type='text' name='freeno' />
		  </p>
		  <input type='hidden' name='user' value='".$usrnm."' />
		  <p>
			<input type='submit' name='submit' value='Kirim' />&nbsp;
            <input type='button' value='Batal' onclick='self.history.back()' />
		  </p>
          </form>";
     break;
  
  // Form Kirim Pesan Tersimpan 
  case "kirimpesan":
    $edit=mysql_query("SELECT * FROM pesan WHERE id_pesan='$_GET[id]'");
    $r=mysql_fetch_array($edit);

    echo "<div class='componentheading'>Kirim Pesan tersimpan via SMS</div>
          <form method=POST action=$aksi?module=sms&act=sendmsg>
          <input type=hidden name=id value='$r[id_pesan]'>
		  <p>
			<strong>Isi Pesan :</strong><br />
			<textarea name='pesan' class='teks' style='width:600px; height:200px;' readonly='readonly'>$r[pesan]</textarea>
		  </p>
		  <p>
		  <strong>Tujuan :</strong>
		  <table class='boslist'>
			<caption>Pilih Anggota</caption>
			<tr>
				<th><input type='checkbox' name='ckall' onclick='checkedAll()' /></th>
				<th>Nama</th>
				<th>No. HP</th>
			</tr>
		";
		$gl = mysql_query("SELECT * FROM anggota");
		while($rp = mysql_fetch_array($gl)) {
			echo "<tr>
				<td align='center'><input type='checkbox' name='rec[]' value='".$rp[nohp]."' /></td>
				<td>$rp[nama]</td>
				<td>$rp[nohp]</td>
			</tr>";
		}
		echo "
		  </table>
		  </p>
		  <p>
			<input type='submit' name='submit' value='Kirim' />&nbsp;
            <input type='button' value='Batal' onclick='self.history.back()' />
		  </p></form>";
    break;  
}
}
?>
